#include"pcap.h"
#pragma comment ( lib, "wpcap.lib")
#pragma warning(disable:4996)
unsigned int ssstrlen(const char* str)
{
	const char* cp = str;
	while (*cp++);
	return (cp - str - 1);
}

//int hex2char(uint8_t c)
int hex2char(int c)
{
	return ((c >= '0') && (c <= '9')) ? int(c - '0') :
		((c >= 'A') && (c <= 'F')) ? int(c - 'A' + 10) :
		((c >= 'a') && (c <= 'f')) ? int(c - 'a' + 10) :
		-1;
}

int Hex2Ascii(char* hex, char* ascii)
{
	int hexLen = ssstrlen(hex);
	int asciiLen = 0;

	for (int i = 0, cnt = 0; i < hexLen; i++)
	{
		char c = hex2char(hex[i]);

		if (-1 == c)
			continue;
		if (cnt) {
			cnt = 0;
			ascii[asciiLen++] += c;
		}
		else {
			cnt = 1;
			ascii[asciiLen] = c << 4;
		}
	}
	ascii[asciiLen++] = 0;
	return asciiLen;
}